package pddxueba;

import java.util.Scanner;

/**
 * Created by JiaJia on 2019/7/28 0028.
 */
public class Shengxu {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String s1=scanner.nextLine();
        String arr1[]=s1.split(" ");
        int[] num1=new int[arr1.length];
        for (int i = 0; i <arr1.length ; i++) {
            num1[i]=Integer.parseInt(arr1[i]);
        }
        String s2=scanner.nextLine();
        String arr2[]=s2.split(" ");
        int[] num2=new int[arr2.length];
        for (int i = 0; i <arr2.length ; i++) {
            num2[i]=Integer.parseInt(arr2[i]);
        }
        //System.out.println(num1);

        System.out.println(check(num1,num2));
    }
    private static int[] check(int[] num1,int[] num2){
        int count=0;
        for (int i = 1; i <num1.length&&count<2 ; i++) {
            if (num1[i]>num1[i-1]){
                continue;
            }
            count++;
            while (count<2){
                for (int j = 0; j <num2.length ; j++) {
                    if (num2[j]>num1[i-2]&&num2[j]<num1[i]){
                        num1[i-1]=num2[j];
                    }
                }
            }
        }
        return num1;
    }


}